home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Simulation / PDP-8 Simulator / Source Code / PDPVectors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-02  |  6.7 KB  |  319 lines  |  [TEXT/KAHL]

  1. /*************************************************************************************
  2. *
  3. *        Generic Appshell- a system 7.0 compatible application shell
  4. *
  5. *        ©1992 Graham Cox. All Rights Reserved.
  6. *
  7. *        This file contains code which may require modification to incorporate your
  8. *        application's functionality. This works closely with Generic_Main to implement
  9. *        the basic application shell. Always place these two files in the same segment.
  10. *
  11. *        Modification History:
  12. *        10/2/92 created from scratch.    
  13. *
  14. *
  15. *
  16. *************************************************************************************/
  17.  
  18. #include    "PDPGlobalEqu.p"
  19. #include    "AppleEvents.h"
  20.  
  21. #include "PDPVectors.proto.h"
  22.  
  23. extern    MenuHandle        AppMenus[NumMenus];            /* Handles to the menus */
  24. extern    short        done;
  25. extern    int            AssemblyDest;
  26.  
  27. GrafPtr    StatBarGrafix;                                /* offscreen port with buttons in it */
  28.  
  29. GrafPtr         MakeAPort(int pictID,int pixDepth);
  30. ControlHandle    GetMemScrollbar(WindowPtr theWindow);
  31. char            IsEditKind(WindowPtr theWindow);
  32.  
  33.  
  34. AppInitialize(void)
  35. {
  36.     /* application initialisation. Use this routine to create menu list, windows, etc */
  37.     
  38.     int            index;
  39.     MenuHandle    temp;
  40.     
  41.     for (index = appleMenu;index < NumMenus;index++) {
  42.         temp = GetMenu(standardResID+index);
  43.         if (temp != NIL) {
  44.             AppMenus[index] = temp;
  45.             InsertMenu(AppMenus[index],0);
  46.         }
  47.     }
  48.     if (AppMenus[appleMenu] != NIL)
  49.         AddResMenu(AppMenus[appleMenu],'DRVR');
  50.         
  51.     CheckItem(AppMenus[asmMenu],ItemToDisk+AssemblyDest,TRUE);
  52.     DrawMenuBar();
  53.     
  54.     StatBarGrafix = MakeAPort(130,0);
  55.     
  56. }
  57.  
  58.  
  59. DispatchMenu(long mSelect)
  60. {
  61.     /* called for menu selection to dispatch commands. Menu ID must be same as original
  62.         resource ID */
  63.     
  64.     int            theMenu,theItem,DARef;
  65.     Str255        DAName;
  66.     GrafPtr        savePort;
  67.     MenuHandle    mH;
  68.     
  69.     theMenu = HiWord(mSelect);
  70.     theItem = LoWord(mSelect);
  71.     
  72.     switch (theMenu-standardResID) {
  73.         case appleMenu:
  74.             if (theItem == ItemAbout) {
  75.                 SetDAFont(geneva);
  76.                 DoAbout();
  77.                 SetDAFont(0);
  78.             }
  79.             else {
  80.                 GetItem(AppMenus[appleMenu],theItem,&DAName);
  81.                 GetPort(&savePort);
  82.                 DARef = OpenDeskAcc(&DAName);
  83.                 SetPort(savePort);
  84.             }
  85.             break;
  86.         case fileMenu:
  87.             FileMenu(theItem);
  88.             break;
  89.         case editMenu:
  90.             EditMenu(theItem);
  91.             break;
  92.         case pdpMenu:
  93.             PDPMenu(theItem);
  94.             break;
  95.         case asmMenu:
  96.             mH = GetMHandle(theMenu);
  97.             AssembleMenu(mH,theItem);
  98.         default:
  99.             break;
  100.     }
  101. }
  102.  
  103.  
  104. DoAbout(void)
  105. {
  106.     /* puts up about dialog box */
  107.  
  108.     int        aboutHit;
  109.     
  110.     aboutHit = xAlert(standardResID,NIL);
  111. }
  112.  
  113.  
  114. ClickTheWindow(WindowPtr theWindow,Point clickPt)
  115. {
  116.     /* called when window clicked in content region. clickPt is in global coordinates */
  117.     
  118.     GrafPtr        savePort;
  119.     
  120.     if (theWindow != NIL) {
  121.         if (theWindow != FrontWindow())
  122.             SelectWindow(theWindow);
  123.         else {
  124.             GetPort(&savePort);
  125.             SetPort(theWindow);
  126.             GlobalToLocal(&clickPt);
  127.             
  128.             if (IsSimulator(theWindow))
  129.                 ClickSimWindow(theWindow,clickPt);
  130.             else
  131.                 if (IsEditKind(theWindow))
  132.                     ClickEditWindow(theWindow,clickPt);
  133.             SetPort(savePort);
  134.         }
  135.     }
  136. }
  137.  
  138.  
  139. DragTheWindow(WindowPtr theWindow,Point dragPt)
  140. {
  141.     /* drags the window. dragPt is in global coordinates */
  142.     
  143.     Rect        dragBounds;
  144.     RgnHandle    deskTopRgn;
  145.     
  146.     if (theWindow != NIL) {
  147.         deskTopRgn = GetGrayRgn();
  148.         if (deskTopRgn != NIL)
  149.             dragBounds = (*deskTopRgn)->rgnBBox;
  150.         else {
  151.             dragBounds = screenBits.bounds;
  152.             dragBounds.top += MBarHeight;
  153.         }
  154.             
  155.         InsetRect(&dragBounds,4,4);
  156.         
  157.         DragWindow(theWindow,dragPt,&dragBounds);
  158.     }
  159. }
  160.  
  161.  
  162. GrowTheWindow(WindowPtr theWindow,Point growPt)
  163. {
  164.     /* resizes the window. growPt is in global coordinates */
  165.     
  166.     Rect        sizeRect,sbRect;
  167.     RgnHandle    sBarRgn,wpRgn;
  168.     long        growSize;
  169.     GrafPtr        savePort;
  170.     
  171.     if (theWindow != NIL) {
  172.         GetPort(&savePort);
  173.         SetPort(theWindow);
  174.         sizeRect = screenBits.bounds;
  175.         sizeRect.top = 100;                    /* min vertical size */
  176.         sizeRect.left = 200;                /* min horizontal size */
  177.         
  178.         growSize = GrowWindow(theWindow,growPt,&sizeRect);
  179.         
  180.         if (growSize != 0) {
  181.             if (IsSimulator(theWindow))
  182.                 ResizeWindow(theWindow,LoWord(growSize),HiWord(growSize));
  183.             if (IsEditKind(theWindow))
  184.                 ResizeEdWindow(theWindow,LoWord(growSize),HiWord(growSize));
  185.         }
  186.  
  187.         SetPort(savePort);
  188.     }
  189. }
  190.  
  191.  
  192. CloseTheWindow(WindowPtr theWindow)
  193. {
  194.     if (IsSimulator(theWindow))
  195.         DisposeProcessWindow(theWindow);
  196.     if (IsEditKind(theWindow))
  197.         DisposeEditWindow(theWindow);
  198. }
  199.  
  200.  
  201. ZoomTheWindow(WindowPtr theWindow,int partCode)
  202. {
  203.     /* zooms window- you may need to do more for scrollbars, etc */
  204.  
  205.     GrafPtr        savePort;
  206.     
  207.     if (theWindow != NIL) {
  208.         GetPort(&savePort);
  209.         SetPort(theWindow);
  210.         EraseRect(&theWindow->portRect);
  211.         if (IsSimulator(theWindow))
  212.             ZoomScrollWindow(theWindow,partCode,TRUE);
  213.         if (IsEditKind(theWindow))
  214.             ZoomEdScrollWindow(theWindow,partCode,TRUE);
  215.         InvalRect(&theWindow->portRect);
  216.         SetPort(savePort);
  217.     }
  218. }
  219.  
  220.  
  221. DrawTheWindow(WindowPtr theWindow)
  222. {
  223.     /* draws the window's contents. Window is current port with correct visRgn, etc.
  224.         This is entirely application dependent! */
  225.     
  226.     if (IsSimulator(theWindow))
  227.         DrawPDPWindow(theWindow);
  228.     if (IsEditKind(theWindow))
  229.         DrawEditWindow(theWindow);
  230.     DrawControls(theWindow);    
  231.     DrawGrowIcon(theWindow);
  232. }
  233.  
  234.  
  235. ActivateTheWindow(WindowPtr theWindow)
  236. {
  237.     /* called when theWindow becomes active */
  238.     ControlHandle    mBar,hBar;
  239.     
  240.     if (theWindow != NIL) {
  241.         SetPort(theWindow);
  242.         DrawGrowIcon(theWindow);
  243.         if (IsSimulator(theWindow))
  244.             mBar = GetMemScrollbar(theWindow);
  245.         else
  246.             if (IsEditKind(theWindow)) {
  247.                 GetScrollBars(theWindow,&mBar,&hBar);
  248.                 if (hBar != NIL)
  249.                     HiliteControl(hBar,0);
  250.             }
  251.         if (mBar != NIL)
  252.             HiliteControl(mBar,0);
  253.     }
  254. }
  255.  
  256.  
  257. DeactivateTheWindow(WindowPtr theWindow)
  258. {
  259.     /* called when theWindow is deactivated */
  260.     ControlHandle    mBar,hBar;
  261.     
  262.     DrawGrowIcon(theWindow);
  263.     if (IsSimulator(theWindow))
  264.         mBar = GetMemScrollbar(theWindow);
  265.     else
  266.         if (IsEditKind(theWindow)) {
  267.             GetScrollBars(theWindow,&mBar,&hBar);
  268.             if (hBar != NIL)
  269.                 HiliteControl(hBar,255);
  270.         }
  271.     if (mBar != NIL)
  272.         HiliteControl(mBar,255);
  273. }
  274.  
  275.  
  276. ResumeApplication(void)
  277. {
  278.     /* called when application resumed under multifinder */
  279.     
  280. }
  281.  
  282.  
  283. SuspendApplication(void)
  284. {
  285.     /* called when application suspended under multifinder */
  286.     
  287. }
  288.  
  289.  
  290. pascal OSErr   OpenApplication(AppleEvent *theAEvt,AppleEvent *reply,long hRefCon)
  291. {
  292.     /* required apple event handler for open application- normally calls New */
  293.     OpenNewWindow();
  294.     return(noErr);        
  295. }
  296.         
  297.  
  298. pascal OSErr   OpenDocuments(AppleEvent *theAEvt,AppleEvent *reply,long hRefCon)
  299. {
  300.     /* required apple event handler for open docs- normally calls Open */
  301.     return(noErr);        
  302. }
  303.         
  304.  
  305. pascal OSErr   PrintDocuments(AppleEvent *theAEvt,AppleEvent *reply,long hRefCon)
  306. {
  307.     /* required apple event handler for printing docs- normally calls Print */
  308.     return(noErr);        
  309.     
  310. }
  311.  
  312.  
  313. pascal OSErr   QuitApplication(AppleEvent *theAEvt,AppleEvent *reply,long hRefCon)
  314. {
  315.     /* required apple event handler for quit application */
  316.     return(noErr);        
  317.     
  318. }
  319.